package mvc_generator.generator.car.jsf;

import com.google.common.base.Objects;
import mvc_generator.mVCGenerator.ArithmeticExpression;
import mvc_generator.mVCGenerator.ArithmeticPrimitive;
import mvc_generator.mVCGenerator.ArithmeticVariable;
import mvc_generator.mVCGenerator.BooleanExpression;
import mvc_generator.mVCGenerator.BooleanPrimitive;
import mvc_generator.mVCGenerator.BooleanVariable;
import mvc_generator.mVCGenerator.DoubleExpression;
import mvc_generator.mVCGenerator.Expression;
import mvc_generator.mVCGenerator.IntegerExpression;
import mvc_generator.mVCGenerator.ParenthesizedArithmeticExpression;
import mvc_generator.mVCGenerator.ParenthesizedBooleanExpression;
import mvc_generator.mVCGenerator.StringExpression;
import mvc_generator.mVCGenerator.StringLengthExpression;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtend2.lib.StringConcatenation;

@SuppressWarnings("all")
public class ExpressionGenerator {
  public CharSequence generate(final Expression expression) {
    CharSequence _xblockexpression = null;
    {
      StringConcatenation _builder = new StringConcatenation();
      CharSequence result = _builder;
      CharSequence _xifexpression = null;
      if ((expression instanceof BooleanExpression)) {
        CharSequence _generate = this.generate(((BooleanExpression) expression));
        CharSequence _result = result = _generate;
        _xifexpression = _result;
      } else {
        CharSequence _xifexpression_1 = null;
        if ((expression instanceof ArithmeticExpression)) {
          CharSequence _generate_1 = this.generate(((ArithmeticExpression) expression));
          CharSequence _result_1 = result = _generate_1;
          _xifexpression_1 = _result_1;
        } else {
          StringConcatenation _builder_1 = new StringConcatenation();
          _builder_1.append("@Auto_Generated: ");
          Class<? extends Expression> _class = expression.getClass();
          String _name = _class.getName();
          _builder_1.append(_name, "");
          _builder_1.append(" is not a handled expression.");
          CharSequence _result_2 = result = _builder_1;
          _xifexpression_1 = _result_2;
        }
        _xifexpression = _xifexpression_1;
      }
      _xblockexpression = (_xifexpression);
    }
    return _xblockexpression;
  }
  
  private CharSequence generate(final BooleanExpression booleanExpression) {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence result = _builder;
    EObject _op1 = booleanExpression.getOp1();
    if ((_op1 instanceof BooleanVariable)) {
      EObject _op1_1 = booleanExpression.getOp1();
      CharSequence _generate = this.generate(((BooleanVariable) _op1_1));
      result = _generate;
    } else {
      EObject _op1_2 = booleanExpression.getOp1();
      if ((_op1_2 instanceof BooleanPrimitive)) {
        EObject _op1_3 = booleanExpression.getOp1();
        CharSequence _generate_1 = this.generate(((BooleanPrimitive) _op1_3));
        result = _generate_1;
      } else {
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("@AutoGenerated_Error: ");
        EObject _op1_4 = booleanExpression.getOp1();
        Class<? extends EObject> _class = _op1_4.getClass();
        String _name = _class.getName();
        _builder_1.append(_name, "");
        _builder_1.append(" is not a handled expression.");
        result = _builder_1;
      }
    }
    String _symbol = booleanExpression.getSymbol();
    boolean _notEquals = (!Objects.equal(_symbol, null));
    if (_notEquals) {
      StringConcatenation _builder_2 = new StringConcatenation();
      _builder_2.append(" ");
      String _symbol_1 = booleanExpression.getSymbol();
      _builder_2.append(_symbol_1, " ");
      _builder_2.append(" ");
      String _plus = (result + _builder_2.toString());
      result = _plus;
      EObject _op2 = booleanExpression.getOp2();
      if ((_op2 instanceof BooleanVariable)) {
        StringConcatenation _builder_3 = new StringConcatenation();
        EObject _op2_1 = booleanExpression.getOp2();
        CharSequence _generate_2 = this.generate(((BooleanVariable) _op2_1));
        _builder_3.append(_generate_2, "");
        String _plus_1 = (result + _builder_3.toString());
        result = _plus_1;
      } else {
        EObject _op2_2 = booleanExpression.getOp2();
        if ((_op2_2 instanceof BooleanPrimitive)) {
          StringConcatenation _builder_4 = new StringConcatenation();
          EObject _op2_3 = booleanExpression.getOp2();
          CharSequence _generate_3 = this.generate(((BooleanPrimitive) _op2_3));
          _builder_4.append(_generate_3, "");
          String _plus_2 = (result + _builder_4.toString());
          result = _plus_2;
        } else {
          EObject _op2_4 = booleanExpression.getOp2();
          if ((_op2_4 instanceof ParenthesizedBooleanExpression)) {
            StringConcatenation _builder_5 = new StringConcatenation();
            EObject _op2_5 = booleanExpression.getOp2();
            CharSequence _generate_4 = this.generate(((ParenthesizedBooleanExpression) _op2_5));
            _builder_5.append(_generate_4, "");
            String _plus_3 = (result + _builder_5.toString());
            result = _plus_3;
          } else {
            StringConcatenation _builder_6 = new StringConcatenation();
            _builder_6.append("@AutoGenerated_Error: ");
            EObject _op2_6 = booleanExpression.getOp2();
            Class<? extends EObject> _class_1 = _op2_6.getClass();
            String _name_1 = _class_1.getName();
            _builder_6.append(_name_1, "");
            _builder_6.append(" is not a handled expression.");
            result = _builder_6;
          }
        }
      }
    }
    return result;
  }
  
  private CharSequence generate(final ArithmeticExpression arithmeticExpression) {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence result = _builder;
    EObject _op1 = arithmeticExpression.getOp1();
    if ((_op1 instanceof ArithmeticVariable)) {
      EObject _op1_1 = arithmeticExpression.getOp1();
      CharSequence _generate = this.generate(((ArithmeticVariable) _op1_1));
      result = _generate;
    } else {
      EObject _op1_2 = arithmeticExpression.getOp1();
      if ((_op1_2 instanceof ArithmeticPrimitive)) {
        EObject _op1_3 = arithmeticExpression.getOp1();
        CharSequence _generate_1 = this.generate(((ArithmeticPrimitive) _op1_3));
        result = _generate_1;
      } else {
        EObject _op1_4 = arithmeticExpression.getOp1();
        if ((_op1_4 instanceof StringLengthExpression)) {
          EObject _op1_5 = arithmeticExpression.getOp1();
          CharSequence _generate_2 = this.generate(((StringLengthExpression) _op1_5));
          result = _generate_2;
        } else {
          StringConcatenation _builder_1 = new StringConcatenation();
          _builder_1.append("@AutoGenerated_Error: ");
          EObject _op1_6 = arithmeticExpression.getOp1();
          Class<? extends EObject> _class = _op1_6.getClass();
          String _name = _class.getName();
          _builder_1.append(_name, "");
          _builder_1.append(" is not a handled expression.");
          result = _builder_1;
        }
      }
    }
    String _symbol = arithmeticExpression.getSymbol();
    boolean _notEquals = (!Objects.equal(_symbol, null));
    if (_notEquals) {
      StringConcatenation _builder_2 = new StringConcatenation();
      _builder_2.append(" ");
      String _symbol_1 = arithmeticExpression.getSymbol();
      _builder_2.append(_symbol_1, " ");
      _builder_2.append(" ");
      String _plus = (result + _builder_2.toString());
      result = _plus;
      EObject _op2 = arithmeticExpression.getOp2();
      if ((_op2 instanceof ArithmeticVariable)) {
        StringConcatenation _builder_3 = new StringConcatenation();
        EObject _op2_1 = arithmeticExpression.getOp2();
        CharSequence _generate_3 = this.generate(((ArithmeticVariable) _op2_1));
        _builder_3.append(_generate_3, "");
        String _plus_1 = (result + _builder_3.toString());
        result = _plus_1;
      } else {
        EObject _op2_2 = arithmeticExpression.getOp2();
        if ((_op2_2 instanceof ArithmeticPrimitive)) {
          StringConcatenation _builder_4 = new StringConcatenation();
          EObject _op2_3 = arithmeticExpression.getOp2();
          CharSequence _generate_4 = this.generate(((ArithmeticPrimitive) _op2_3));
          _builder_4.append(_generate_4, "");
          String _plus_2 = (result + _builder_4.toString());
          result = _plus_2;
        } else {
          EObject _op1_7 = arithmeticExpression.getOp1();
          if ((_op1_7 instanceof StringLengthExpression)) {
            StringConcatenation _builder_5 = new StringConcatenation();
            EObject _op1_8 = arithmeticExpression.getOp1();
            CharSequence _generate_5 = this.generate(((StringLengthExpression) _op1_8));
            _builder_5.append(_generate_5, "");
            String _plus_3 = (result + _builder_5.toString());
            result = _plus_3;
          } else {
            EObject _op2_4 = arithmeticExpression.getOp2();
            if ((_op2_4 instanceof ParenthesizedArithmeticExpression)) {
              StringConcatenation _builder_6 = new StringConcatenation();
              EObject _op2_5 = arithmeticExpression.getOp2();
              CharSequence _generate_6 = this.generate(((ParenthesizedArithmeticExpression) _op2_5));
              _builder_6.append(_generate_6, "");
              String _plus_4 = (result + _builder_6.toString());
              result = _plus_4;
            } else {
              StringConcatenation _builder_7 = new StringConcatenation();
              _builder_7.append("@AutoGenerated_Error: ");
              EObject _op2_6 = arithmeticExpression.getOp2();
              Class<? extends EObject> _class_1 = _op2_6.getClass();
              String _name_1 = _class_1.getName();
              _builder_7.append(_name_1, "");
              _builder_7.append(" is not a handled expression.");
              result = _builder_7;
            }
          }
        }
      }
    }
    return result;
  }
  
  private CharSequence generate(final ArithmeticVariable arithmeticVariable) {
    StringConcatenation _builder = new StringConcatenation();
    String _refer = arithmeticVariable.getRefer();
    _builder.append(_refer, "");
    return _builder;
  }
  
  private CharSequence generate(final StringLengthExpression stringLengthExpression) {
    StringConcatenation _builder = new StringConcatenation();
    String result = _builder.toString();
    EObject _expression = stringLengthExpression.getExpression();
    if ((_expression instanceof StringExpression)) {
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("\"");
      EObject _expression_1 = stringLengthExpression.getExpression();
      String _value = ((StringExpression) _expression_1).getValue();
      _builder_1.append(_value, "");
      _builder_1.append("\".length()");
      result = _builder_1.toString();
    } else {
      EObject _expression_2 = stringLengthExpression.getExpression();
      if ((_expression_2 instanceof ArithmeticVariable)) {
        StringConcatenation _builder_2 = new StringConcatenation();
        EObject _expression_3 = stringLengthExpression.getExpression();
        String _refer = ((ArithmeticVariable) _expression_3).getRefer();
        _builder_2.append(_refer, "");
        _builder_2.append(".length()");
        result = _builder_2.toString();
      }
    }
    return result;
  }
  
  private CharSequence generate(final ArithmeticPrimitive arithmeticPrimitive) {
    CharSequence _xifexpression = null;
    if ((arithmeticPrimitive instanceof IntegerExpression)) {
      StringConcatenation _builder = new StringConcatenation();
      int _value = ((IntegerExpression) arithmeticPrimitive).getValue();
      _builder.append(_value, "");
      _xifexpression = _builder;
    } else {
      CharSequence _xifexpression_1 = null;
      if ((arithmeticPrimitive instanceof DoubleExpression)) {
        StringConcatenation _builder_1 = new StringConcatenation();
        int _value_1 = ((DoubleExpression) arithmeticPrimitive).getValue();
        _builder_1.append(_value_1, "");
        _builder_1.append(".");
        int _decimalValue = ((DoubleExpression) arithmeticPrimitive).getDecimalValue();
        _builder_1.append(_decimalValue, "");
        _xifexpression_1 = _builder_1;
      } else {
        CharSequence _xifexpression_2 = null;
        if ((arithmeticPrimitive instanceof StringExpression)) {
          StringConcatenation _builder_2 = new StringConcatenation();
          _builder_2.append("\"");
          String _value_2 = ((StringExpression) arithmeticPrimitive).getValue();
          _builder_2.append(_value_2, "");
          _builder_2.append("\"");
          _xifexpression_2 = _builder_2;
        } else {
          StringConcatenation _builder_3 = new StringConcatenation();
          _builder_3.append("@AutoGenerated_Error: ");
          Class<? extends ArithmeticPrimitive> _class = arithmeticPrimitive.getClass();
          String _name = _class.getName();
          _builder_3.append(_name, "");
          _builder_3.append(" is not a handled ArithmeticPrimitive.");
          _xifexpression_2 = _builder_3;
        }
        _xifexpression_1 = _xifexpression_2;
      }
      _xifexpression = _xifexpression_1;
    }
    return _xifexpression;
  }
  
  private CharSequence generate(final ParenthesizedArithmeticExpression parenthesizedArithmeticExpression) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("(");
    ArithmeticExpression _expression = parenthesizedArithmeticExpression.getExpression();
    CharSequence _generate = this.generate(_expression);
    _builder.append(_generate, "");
    _builder.append(")");
    return _builder;
  }
  
  private CharSequence generate(final BooleanVariable booleanVariable) {
    StringConcatenation _builder = new StringConcatenation();
    String _refer = booleanVariable.getRefer();
    _builder.append(_refer, "");
    return _builder;
  }
  
  private CharSequence generate(final BooleanPrimitive booleanPrimitive) {
    StringConcatenation _builder = new StringConcatenation();
    String _value = booleanPrimitive.getValue();
    _builder.append(_value, "");
    return _builder;
  }
  
  private CharSequence generate(final ParenthesizedBooleanExpression parenthesizedBooleanExpression) {
    StringConcatenation _builder = new StringConcatenation();
    BooleanExpression _expression = parenthesizedBooleanExpression.getExpression();
    CharSequence _generate = this.generate(_expression);
    _builder.append(_generate, "");
    return _builder;
  }
}
